package what.basic.textcomponent;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.*;
public class Jtextpane {
private JTextPane tp;
public Jtextpane(){
	tp=new JTextPane();
	tp.setBackground(Color.lightGray);
	tp.setEditable(true);
}
public void setRED_Bold_20(String str){
	SimpleAttributeSet attset=new SimpleAttributeSet();
	StyleConstants.setForeground(attset, Color.red);
	StyleConstants.setBold(attset, true);
	insert(str,attset);
}

public void setGREEN_Italic_30(String str){
	SimpleAttributeSet attset=new SimpleAttributeSet();
	StyleConstants.setForeground(attset, Color.green);
	StyleConstants.setItalic(attset, true);
	StyleConstants.setFontSize(attset, 30);
	insert(str,attset);
}

public void setBLACK_Underline_Italic_40(String str){
	SimpleAttributeSet attset=new SimpleAttributeSet();
	StyleConstants.setForeground(attset, Color.black);
	StyleConstants.setItalic(attset, true);
	StyleConstants.setUnderline(attset, true);
	StyleConstants.setFontSize(attset, 40);
	insert(str,attset);
}

private void insert(String str, SimpleAttributeSet attset) {
	Document doc=tp.getDocument();
	str=str+"\n";
	try{
		doc.insertString(doc.getLength(), str, attset);
	}
	catch(BadLocationException ble){
		System.out.println("BadLocationException:"+ble);
	}
}
public Component getComponent(){
	return tp;
}
public static void main(String[] args) {
Jtextpane jtp=new Jtextpane();
jtp.setRED_Bold_20("oddddddweeeeeeeeeeee");
jtp.setGREEN_Italic_30("x000000000000000000333");
jtp.setBLACK_Underline_Italic_40("xclc,,mmn33nsssdl");
JFrame f=new JFrame("jtextpane");
f.getContentPane().add(jtp.getComponent());
f.setSize(450,180);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
	public void windowClosing(WindowEvent e){
		System.exit(0);
	}
});
	}

}
